package java_thread;

/**
 * 死锁程序
 */
public class demo_21_deadlock {
    public static void main(String[] args) {
        new Thread(() -> {
            try {
                System.out.println("thread1 is running");
                synchronized (demo_21_deadlock.class) {
                    System.out.println("thread1 is block obj1");

                    Thread.sleep(1000);
                    synchronized (Object.class) {
                        System.out.println("thread1 is block ojb2");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(() -> {
            try {
                System.out.println("thread2 is running");
                synchronized (Object.class) {
                    System.out.println("thread2 is block obj1");

                    Thread.sleep(1000);
                    synchronized (demo_21_deadlock.class) {
                        System.out.println("thread2 is block ojb2");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
    }
}
